﻿package mortal.game.view.systemSetting.view
{
    import __AS3__.vec.*;
    import com.mui.controls.*;
    import fl.controls.*;
    import flash.events.*;
    import mortal.game.manager.*;
    import mortal.game.scene3D.map3D.util.*;
    import mortal.game.view.common.*;
    import mortal.game.view.systemSetting.data.*;

    public class SystemSetItem extends GSprite
    {
        protected var _checkBox:GCheckBox;
        protected var _numInput:NumInput;
        protected var _radioButtonGroup:RadioButtonGroup;
        protected var _radioButtons:Vector.<GRadioButton>;
        protected var __height:Number = 0;
        protected var _settingItem:SettingItem;

        public function SystemSetItem()
        {
            return;
        }// end function

        public function set data(param1:SettingItem) : void
        {
            this.disposeImpl();
            this._settingItem = param1;
            switch(param1.valueType)
            {
                case SettingItem.BOOLEAN:
                {
                    this.createCheckBox();
                    break;
                }
                case SettingItem.INT:
                {
                    this.createInput();
                    break;
                }
                case SettingItem.SELECT:
                {
                    this.createRadioBox();
                    break;
                }
                default:
                {
                    break;
                }
            }
            return;
        }// end function

        public function refreshDisplay() : void
        {
            var _loc_1:Array = null;
            var _loc_2:int = 0;
            var _loc_3:int = 0;
            var _loc_4:Object = null;
            var _loc_5:GRadioButton = null;
            switch(this._settingItem.valueType)
            {
                case SettingItem.BOOLEAN:
                {
                    this._checkBox.selected = Boolean(this._settingItem.displayValue);
                    break;
                }
                case SettingItem.INT:
                {
                    if (this._settingItem.displayValue < 0)
                    {
                        this._numInput.currentNum = int(this._settingItem.extend.def);
                    }
                    else
                    {
                        this._numInput.currentNum = this._settingItem.displayValue;
                    }
                    break;
                }
                case SettingItem.SELECT:
                {
                    _loc_1 = this._settingItem.extend as Array;
                    _loc_2 = _loc_1.length;
                    _loc_3 = 0;
                    while (_loc_3 < _loc_2)
                    {
                        
                        _loc_4 = _loc_1[_loc_3];
                        _loc_5 = this._radioButtons[_loc_3];
                        if (_loc_5.value == this._settingItem.displayValue)
                        {
                            _loc_5.selected = true;
                        }
                        _loc_3++;
                    }
                    break;
                }
                default:
                {
                    break;
                }
            }
            return;
        }// end function

        protected function createCheckBox() : void
        {
            this._checkBox = UIFactory.checkBox(this._settingItem.desStr, 0, 0, 200, 28, this);
            this._checkBox.selected = Boolean(this._settingItem.displayValue);
            this._checkBox.configEventListener(Event.CHANGE, this.onSelectCheckBox);
            this.__height = 28;
            return;
        }// end function

        private function onSelectCheckBox(event:Event) : void
        {
            if (GameMapUtil.curMapState.isHeroArenaMap)
            {
                MsgManager.showRollTipsMsg("竞技场中不能屏蔽");
                return;
            }
            this._settingItem.displayValue = this._checkBox.selected ? (1) : (0);
            dispatchEvent(new Event(Event.CHANGE));
            return;
        }// end function

        protected function createInput() : void
        {
            this._numInput = UIFactory.numInput(25, 0, this);
            this._numInput.minNum = int(this._settingItem.extend.min);
            this._numInput.maxNum = int(this._settingItem.extend.max);
            this._numInput.configEventListener(Event.CHANGE, this.onUpdateIntValue);
            if (this._settingItem.displayValue < 0)
            {
                this._numInput.currentNum = int(this._settingItem.extend.def);
            }
            else
            {
                this._numInput.currentNum = this._settingItem.displayValue;
            }
            this.__height = 28;
            return;
        }// end function

        private function onUpdateIntValue(event:Event = null) : void
        {
            this._settingItem.displayValue = this._numInput.currentNum;
            return;
        }// end function

        protected function createRadioBox() : void
        {
            var _loc_4:Object = null;
            var _loc_5:GRadioButton = null;
            this._radioButtons = new Vector.<GRadioButton>;
            this._radioButtonGroup = new RadioButtonGroup("systemSet" + this._settingItem.key);
            var _loc_1:* = this._settingItem.extend as Array;
            var _loc_2:* = _loc_1.length;
            var _loc_3:int = 0;
            while (_loc_3 < _loc_2)
            {
                
                _loc_4 = _loc_1[_loc_3];
                _loc_5 = UIFactory.radioButton(_loc_4.text, 20, 28 * _loc_3, 180, 28, this);
                _loc_5.value = _loc_4.value;
                _loc_5.group = this._radioButtonGroup;
                _loc_5.selected = false;
                if (_loc_3 == 0)
                {
                    _loc_5.selected = true;
                }
                this._radioButtons.push(_loc_5);
                _loc_3++;
            }
            if (this._settingItem.displayValue > 0)
            {
                this._radioButtonGroup.selectedData = this._settingItem.displayValue;
            }
            else
            {
                this._radioButtons[0].selected = true;
            }
            this.__height = _loc_2 * 28;
            this._radioButtonGroup.addEventListener(Event.CHANGE, this.onRadioButtonChage);
            return;
        }// end function

        protected function onRadioButtonChage(event:Event) : void
        {
            this.updateRadioDisplayValue();
            return;
        }// end function

        protected function updateRadioDisplayValue() : void
        {
            this._settingItem.displayValue = int(this._radioButtonGroup.selectedData);
            return;
        }// end function

        override public function get height() : Number
        {
            return this.__height;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            var _loc_2:int = 0;
            var _loc_3:int = 0;
            super.disposeImpl(param1);
            this._settingItem = null;
            if (this._checkBox)
            {
                this._checkBox.dispose(param1);
                this._checkBox = null;
            }
            if (this._numInput)
            {
                this._numInput.dispose(param1);
                this._numInput = null;
            }
            if (this._radioButtonGroup)
            {
                if (this._radioButtons)
                {
                    _loc_2 = this._radioButtons.length;
                    _loc_3 = 0;
                    while (_loc_3 < this._radioButtons.length)
                    {
                        
                        this._radioButtonGroup.removeRadioButton(this._radioButtons[_loc_3]);
                        this._radioButtons[_loc_3].dispose(param1);
                        _loc_3++;
                    }
                    this._radioButtons = null;
                }
                this._radioButtonGroup.removeEventListener(Event.CHANGE, this.onRadioButtonChage);
                this._radioButtonGroup = null;
            }
            return;
        }// end function

    }
}
